草庐IT

python - HowTo 基准测试 : Reading Data

全部标签

go - 使用 initilzer 函数创建的结构不会导出到测试包中吗?

假设我们有一个struct和一个类似这样的结构的构造函数packagemyPackagetypeClientstruct{aTypeAbTypeB}funcNewClient(aTypeA,bTypeB)ConcreteClient{return&Client{a:a,b:b,}}typeConcreteClientinterface{ExportedFunc()}func(c*Client)privateFunc(){//...}func(c*Client)ExportedFunc(){//...}我们在这样的测试包中使用这个客户端var(c=&Client{a:a,b:b,})fu

go - 为什么我从 golang 错误地运行 python 脚本

import("fmt""os/exec""bytes")funcmain(){cmd:="/root/hi.py>/root/1.log"out,err:=exec.Command("python","-c",cmd).Output()fmt.Printf("Out:%s",string(out))fmt.Printf("Err:%s",err.Error())}错误:没有这样的文件错误:/root/hi.py>/root/1.log//hi.py#!/usr/bin/pythonprint('helloworld') 最佳答案

unit-testing - 如何测试以确保函数被调用?

我想做单元测试。为了简单起见,我只想确保调用“JWTCheck”。我该怎么做?这是我实现JWTCheck的文件:typeJWTCheckerstruct{SubjectPrefixstring}func(j*JWTChecker)JWTCheck(nexthttp.Handler)http.Handler{//Dosomething}这是我实现路由器的地方:import("net/http""github.com/gorilla/mux")//Routerreturnsapreconfiguredrouterforapplicationfunc(a*Adapter)Router()ht

go - 创建一个函数来测试从接口(interface)编码/解码

我想创建一个简单的函数来测试编码/解码记录是否按预期工作。我只是在这个例子中使用JSON:packagetestimport("encoding/json""fmt""testing""reflect""github.com/stretchr/testify/require")funcCheckRoundTripJSON(t*testing.T,recordinterface{}){data,err:=json.Marshal(record)require.NoError(t,err)fmt.Println("Record:",record,"wasencodedto:",data,"

python - golang 像 python 一样定义 dict,并将值附加到 dict 中的列表

我是新手,正在尝试实现如下所示的类似python的嵌套结构,我无法在golang中定义空字典/映射,它可以包含特定结构/类对象的列表,并且在遍历数据时我不是能够在map/dict中附加项目...我将非常感谢对此的任何帮助...谢谢items=[("item1",someObj1),("item2",someObj2),("item3",someObj3),("item3",someObj5),("item1",someObj4),]rectors={}foritem,objinitems:try:rectors[item].append(obj)exceptKeyError:recto

go - 需要 *os.File 作为参数的测试函数

我想为波纹管函数编写一个测试,但我不明白我可以将什么作为参数发送给toCount,因为我不想打开/创建文件,我知道os.Stdin会起作用,但我认为你不能写入它。functoCount(f*os.File)int{input:=buffo.NewScanner(f)sum:=0;forinput.Scan(){sum++}returnsum} 最佳答案 您的toCount函数只需要一个io.Reader。如果将签名更改为functoCount(fio.Reader)int它可以接受*os.File和任何其他你想用来测试的阅读器。

python - 相当于golang中的itemgetter

我正在将一个程序从python转换为golang,我有一行获取嵌套列表中的第一个值:x_values=map(operator.itemgetter(0),self.coords)此命令将[[1,2],[2,3],[7,4]]转换为[1,2,7]。在go中有类似的东西吗? 最佳答案 Go中的等价物是for循环:packagemainimport("fmt")funcmain(){a:=make([][]int,3)a[0]=[]int{1,2}a[1]=[]int{2,3}a[2]=[]int{7,4}b:=make([]int,l

testing - 如何在 GO 中测试响应体?

我有以下功能:funcSomeFunction(whttp.ResponseWriter,...)error{...returnjson.NewEncoder(w).Encode(&c)}其中c是我的结构。当我运行该函数时,我收到带有json的响应主体,但我无法测试该函数。例如,我有:funcTestSomeFunction(t*testing.T){...w:=httptest.ResponseRecorder{}err:=SomeFunction(w,...)..}在这种情况下,我的w.Body是空的。问题不在于我的功能,因为我在运行时得到了body。我认为我没有以正确的方式进行测

Golang - 在方法中测试 HTTP 请求

谈到在Go中进行测试时,我有点困惑。我读过在某些情况下抽象到接口(interface)应该是理想的方式,在其他情况下我看到了TestTables。我不太确定何时应用其中任何一个。例如,如何测试下面的功能。typeUser{Namestring`json:"name"`IsMarriedbool`json:"isMarried"`Nicknames[]string`json:"nicknames"`}func(u*User)Create()(*http.Response,error){data,err:=json.Marshal(u)iferr!=nil{returnnil,err}ur

根据python在Excel中的某些列中删除重复行

importpandasaspdtoclean=pd.ExcelFile(r'C:\Users\Desktop\NewMicrosoftExcelWorksheet.xlsx',sheetname=0)df4=toclean.drop_duplicates(subset='A',keep='last')df4.save(r'C:\Users\Desktop\final.xlsx')我在Excel中有一些信息,可以说名称DIADADFA32323221122321现在我的输出应该看起来像3232322111看答案以外df4.save(r'c:\users\desktop\final.xlsx')